package com.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Timer;
import java.util.TimerTask;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class WriteToHtml {
	static File name=new File("file.html.zip");
	private static  OutputStream out=null;
	private ZipOutputStream zo=null;
	static Timer timer=new Timer();
	 TimerTask task=new TimerTask() {
		int i=10;
		@Override
		public void run() {
			String s="<br/>abcd"+Math.random()*1000;
			try {
				if(i-->0){
					write(s);
				}else{
					end();
					return;
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	};
	 {
		try {
			timer.schedule(task, 2000, 1000);
			out=new FileOutputStream(name);
			System.out.println("out="+out);
			zo=new ZipOutputStream(out);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
	private void write(String s) throws IOException {
		ZipEntry e=new ZipEntry("file.html");
		zo.putNextEntry(e);
		System.out.println("e="+e);
		System.out.println("name="+name.getAbsolutePath());		
		zo.write(s.getBytes());
		zo.flush();
		System.out.println("OK");
	}
	
	private void end() throws IOException{
		zo.close();
	}
	public static void main(String[] args) {
		new WriteToHtml();
	}
	
}
